package com.mysoft.mapper;

import com.mysoft.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    //根据用户名查询用户
    @Select("select * from big_event.user where username =#{username}")
    User findByUsername(String username);

    //添加用户
    @Insert("insert into big_event.user(username, password, create_time, update_time)"
            +" values (#{username},#{password},now(),now())")
    void add(String username, String password);

    //更新
    @Update("update big_event.user set big_event.user.nickname=#{nickname}," +
            "big_event.user.email=#{email}," +
            "big_event.user.update_time=#{updateTime} where big_event.user.id=#{id}")
    void update(User user);

    //更新头像
    @Update("update big_event.user set big_event.user.user_pic=#{avatarUrl}," +
                   "big_event.user.update_time=now() where big_event.user.id=#{id}")
    void updateAvatar(String avatarUrl, Integer id);

    //更新密码
    @Update("update big_event.user set big_event.user.password=#{md5String}," +
            "big_event.user.update_time=now() where big_event.user.id=#{id}")
    void updatePwd(String md5String, Integer id);
}

